package frontend.visitor.symboltbl;

import ir.values.Value;
import utils.Wrapper;

public class Symbol {
    private Value value;
    private boolean isGlobal;
    private boolean isConst;
    private SymbolConstInitial constInitial;
    public Symbol(Value value) {
        this.value = value;
        this.isGlobal = false;
        this.isConst = false;
        this.constInitial = null;
    }
    public Symbol(Value value, boolean isGlobal, boolean isConst, int initial) {
        this.value = value;
        this.isGlobal = isGlobal;
        this.isConst = isConst;
        this.constInitial = new SymbolConstInitial(initial);
    }

    public Symbol(Value value, boolean isGlobal, boolean isConst, int[] initial, int len) {
        this.value = value;
        this.isGlobal = isGlobal;
        this.isConst = isConst;
        this.constInitial = new SymbolConstInitial(initial, len);
    }

    public Symbol(Value value, boolean isGlobal, boolean isConst, int[][] initial, int len1, int len2) {
        this.value = value;
        this.isGlobal = isGlobal;
        this.isConst = isConst;
        this.constInitial = new SymbolConstInitial(initial, len1, len2);
    }

    public Integer getIntVal(Wrapper<Symbol.ErrorCase> upErrorCase, int... offsets) {
        return this.constInitial.getIntVal(upErrorCase, offsets);
    }

    public Value getValue() {
        return value;
    }

    public boolean isGlobal() {
        return isGlobal;
    }

    public boolean isConst() {
        return isConst;
    }

    public String getName() {
        return value.getOriginalName();
    }

    public enum ErrorCase {
        SUCCESS, OFFSETS_TOO_LONG, OFFSETS_TOO_SHORT, CROSS_THE_BORDER;
    }

    public int getDimension() {
        return constInitial.getDimension();
    }
}
